package com.huwaiwai.jvm.d20200618;

/**
 * @author 歪大哥😁
 * @date 2020-06-18.
 */
public class DeadLockTest {

    public static void main(String[] args) {
        String l1 = "l1";
        String l2 = "l2";
        new DoubleLockThread(l1, l2, "a").start();
        new DoubleLockThread(l2, l1, "b").start();
    }


}

class DoubleLockThread extends Thread {

    private String lock1;
    private String lock2;

    public DoubleLockThread(String l1, String l2, String name) {
        this.lock1 = l1;
        this.lock2 = l2;
        setName(name);
    }

    @Override
    public void run() {

        synchronized (lock1) {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lock2) {
            }
        }
    }
}